package T5;

interface AAA {
    void attack();
}
interface Mobile {
    void move();
}


abstract class Weapon implements AAA, Mobile {
}

class Tank extends Weapon {
    @Override
    public void attack() {
        System.out.println("坦克使用火炮攻击！");
    }

    @Override
    public void move() {
        System.out.println("坦克履带前进！");
    }
}


class BBBB extends Weapon {
    @Override
    public void attack() {
        System.out.println("战斗机发射导弹攻击！");
    }

    @Override
    public void move() {
        System.out.println("战斗机在空中高速飞行！");
    }
}


class WarShip extends Weapon {
    @Override
    public void attack() {
        System.out.println("战舰发射舰炮攻击！");
    }

    @Override
    public void move() {
        System.out.println("战舰在海面上航行！");
    }
}


class Army {
    private Weapon[] w; // 武器数组
    private int count = 0; // 当前武器数量
    public Army(int maxSize) {
        w = new Weapon[maxSize];
    }
    public void addWeapon(Weapon wa) {
        if (count < w.length) {
            w[count++] = wa;
            System.out.println("武器添加成功！");
        } else {
            System.out.println("武器库已满，无法添加更多武器！");
        }
    }
    public void attackAll() {
        System.out.println("--- 所有武器攻击 ---");
        for (int i = 0; i < count; i++) {
            w[i].attack();
        }
    }
    public void moveAll() {
        System.out.println("--- 所有武器移动 ---");
        for (int i = 0; i < count; i++) {
            w[i].move();
        }
    }
}
public class DD {
    public static void main(String[] args) {
        Army army = new Army(5);
        Weapon tank = new Tank();
        Weapon flighter = new BBBB();
        Weapon warShip = new WarShip();
        army.addWeapon(tank);
        army.addWeapon(flighter);
        army.attackAll();
        army.moveAll();
        army.addWeapon(new Tank());
        army.addWeapon(new BBBB());
        army.addWeapon(new WarShip());
        army.attackAll();
        army.moveAll();
    }
}
